package com.example.controller;

import cn.hutool.core.bean.BeanUtil;
import com.example.domain.User;
import com.example.result.JsonResult;
import com.example.result.UserResult;
import com.example.untils.RedisContext;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpSession;
import java.util.Map;

/** 控制器类的基类 */
public class BaseController {
    //** @ExceptionHandler用于统一处理方法抛出的异常 */
    @ExceptionHandler(RuntimeException.class)
    public JsonResult handleException(Throwable e){

        return new JsonResult(false,e.getMessage());
    }
    //获取session中的uid
    public Long getSessionUId(HttpSession session){
        UserResult userResult=(UserResult)session.getAttribute("user");
        return userResult.getUid();
    }
    //获取session中的username
    public String getSessionUsername(HttpSession session){
        UserResult userResult=(UserResult)session.getAttribute("user");
        return userResult.getUsername();
    }
    //获取session中的User
    public UserResult getSessionUser(HttpSession session){
        UserResult userResult=(UserResult)session.getAttribute("user");
        return userResult;
    }
}
